<%-- 
    Document   : index
    Created on : 3 mai 2011, 22:48:42
    Author     : simon
--%>


<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/ecom-web/css/style.css">
        <link rel="shortcut icon" href="/ecom-web/img/favicon.ico">

        <script src="/ecom-web/js/jquery-1.4.2.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="/ecom-web/js/jquery.easing.min.js"></script>
        <script type="text/javascript" src="/ecom-web/js/jquery.lavalamp.min.js"></script>
        <script type="text/javascript">
            $(".lava").lavaLamp({
                fx: "backout",
                speed: 700,
                click: function(event, menuItem) {
                    return true;
                }
            });
        </script>
    </head>

    <body>
        <div id="wrapper">
            <div id="header">


                <div id="logo">Winery<br /><span class="normal">l'art d'acheter le vin!</span></div>

                <div class="">Back office</div>

                <div id="menu">
                    <ul class="lava">
                        <li class=""><a href="/secured/" title="">Accueil</a></li>
                        <li class="<c:if test="${requestScope['javax.servlet.forward.servlet_path'] == '/secured/products'}">current</c:if>"><a href="<c:url value='/secured/products' />" title="">Produits</a></li>
                        <li class="<c:if test="${requestScope['javax.servlet.forward.servlet_path'] == '/secured/stores'}">current</c:if>"><a href="<c:url value='/secured/stores' />" title="">Boutiques</a></li>
                        <li class="<c:if test="${requestScope['javax.servlet.forward.servlet_path'] == '/secured/customers'}">current</c:if>"><a href="<c:url value='/secured/customers' />" title="">Clients</a></li>
                        <li class="<c:if test="${requestScope['javax.servlet.forward.servlet_path'] == '/secured/customers'}">current</c:if>"><a href="<c:url value='/secured/others' />" title="">Autres</a></li>
                    </ul>
                </div> <%-- Menu dans les autres pages que l'index --%>

            </div>

            <c:if test="${infoMessage != null}">
                <div id="infoMessage" class="panelInfo">
                    <div>Message : <c:out value="${infoMessage}"></c:out></div>
                </div>
            </c:if>

            <c:if test="${errorMessage != null}">
                <div id="errorMessage" class="panelInfo">
                    <div>Erreur : <c:out value="${errorMessage}"></c:out></div>
                </div>
            </c:if>


            <div id="content">
                <c:choose>
                    <c:when test="${productList != null}">
                        <h2>Gestion des produits</h2>
                        <a href="<c:url value='/secured/newProduct' />" title="">Ajouter un produit</a>
                        <table>
                            <thead> 
                                <tr> 
                                    <th class="sortable-text">Nom</th> 
                                    <th class="sortable-numeric">Cat&eacute;gorie</th> 
                                    <th class="sortable-text">Description</th> 
                                    <th class="sortable-numeric">Quantité</th> 
                                    <th class="sortable-numeric">Prix</th> 
                                    <th class="sortable-numeric">Nom du magasin</th> 
                                    <th class="sortable-text">Modifier</th> 
                                    <th class="sortable-text">Supprimer</th> 
                                </tr> 
                            </thead> 
                            <tbody>
                                <c:forEach var="product" items="productList">
                                    <tr>
                                        <td>
                                            ${product.name}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            ${product.category.label}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(product.description) > 150}">
                                                    <c:out value="${fn:substring(product.description, 0, 150)}" />...
                                                </c:when>
                                                <c:otherwise>
                                                    <c:out value="${product.description}" />
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            ${product.productStoreList.stock}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            ${product.productStoreList.price}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            ${product.productStoreList.store.name}
                                        </td>
                                    </tr>

                                    <tr>
                                        <td>
                                            <a href="">Modifier</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <a href="/secured/deleteProduct?idproduct=${product.id}/>">Supprimer</a>
                                        </td>
                                    </tr>

                                </c:forEach>
                            </tbody>
                        </table>
                    </c:when>
                    <c:when test="${addProduct != null}">
                        <h2>Ajouter un produit</h2>
                        <form action="/secured/addProduct" method="POST" id="form-product" class="">
                            <div>
                                <label>Nom : </label>
                                <input type="text" name="name" />
                            </div>
                            <div>
                                <label>Description : </label>
                                <input type="text" name="description" />
                            </div>

                            <div>
                                <select name="category" >
                                    <c:forEach var="category" items="${categoryList}">
                                        <option value="${category.id}">${category.label}</option>
                                    </c:forEach>
                                </select>
                            </div>

                            <div>
                                <label>Quantité : </label>
                                <input type="text" name="stock" />
                            </div>    
                            <div>
                                <label>Prix : </label>
                                <input type="text" name="price" />
                            </div>
                            <div>
                                
                                <select name="store" >
                                    <c:forEach var="store" items="${storeList}">
                                        <option value="${store.idStore}">${store.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <input type="hidden" name="addProduct" value="true" />
                            <button type="submit">Enregistrer</button>

                        </form>
                    </c:when>
                </c:choose>




            </div>
        </div>
    </body>
</html>
